home *** CD-ROM | disk | FTP | other *** search
- ;/*
- sc NODEBUG DATA=FAR NOSTKCHK IGNORE=73 IGNORE=147 UNSCHAR STRMERGE NOLINK SmPalette
- slink SmPalette.o ND
- quit
- */
- /*----------------------------------------------------------------------
- This is the Same program as Palette.c, but it compiles to less than
- half it's size. This ispossible simply by removing any startup code.
- This one also will not put up that annoying little window that SAS/C
- startup code creates when it's programs are started from Workbench.
- Notice the WBStartup code is not quite as stated in the RKM
- manuals, it is based off the code in "HowToCode.txt".
-
- Anyway, you can now change the colors on any screen and use
- the AGA's 24 bit palette. The only major change over the last
- palette requester I wrote is that it now uses the actual 3.0 functions
- LoadRGB32(), and GetRGB32() rather than my own home brewed versions.
- You will also notice the additions of Keyboard equivalents, and
- "R", "G", and "B" by the sliders, and the addition of a "Selected Color"
- box on the left side of the Palette gadget.
-
- By the way, I am not rich, but I am not doing this for money
- either. All I ask is if you use or modify this program let me know.
- I am really interested in seeing how far this program gets.
- Do what you want with it.
-
- But if it makes you fell better, I will take cash :-))
- You can guesse the legal matters, "I am not responsible..."
-
- Psychotic Psoftware
- Anthony J. Moringello
- 2209 E. Park Pl. #4
- Miwlaukee, WI 53211
-
- ----------------------------------------------------------------------*/
- /*
- * Source machine generated by GadToolsBox V2.0
- * which is (c) Copyright 1991-1993 Jaba Development
- *
- * GUI Designed by : Anthony J. Moringello - anthonym@csd4.csd.uwm.edu
- */
-
- #include <exec/types.h>
- #include <Exec/Memory.h>
- #include <intuition/intuition.h>
- #include <Intuition/IntuitionBase.h>
- #include <intuition/classes.h>
- #include <intuition/classusr.h>
- #include <intuition/imageclass.h>
- #include <intuition/gadgetclass.h>
- #include <libraries/gadtools.h>
- #include <DOS/DOSExtens.h>
- #include <graphics/displayinfo.h>
- #include <graphics/gfxbase.h>
- #include <clib/exec_protos.h>
- #include <clib/intuition_protos.h>
- #include <clib/gadtools_protos.h>
- #include <clib/graphics_protos.h>
- #include <clib/utility_protos.h>
- #include <CLib/DOS_Protos.h>
- #include <CLib/AGA_Protos.h>
- #include <string.h>
-
- #define ABSEXECBASE ((struct ExecBase **)4L)
-
- struct DOSBase *DOSBase;
- struct IntuitionBase *IntuitionBase;
- struct GfxBase *GfxBase;
- struct GadToolsBase *GadToolsBase;
-
- #include <pragmas/exec_pragmas.h>
- #include <pragmas/intuition_pragmas.h>
- #include <pragmas/gadtools_pragmas.h>
- #include <pragmas/graphics_pragmas.h>
- #include <pragmas/utility_pragmas.h>
- #include <Pragmas/DOS_Pragmas.h>
- #include <Pragmas/AGA_Pragmas.h>
-
- #include "Palette.h"
-
- struct Window *PReqWnd = NULL;
- struct Screen *Scr = NULL;
- struct Gadget *PReqGList = NULL;
- struct IntuiMessage PReqMsg;
- struct Gadget *PReqGadgets[7];
- APTR VisualInfo = NULL;
- UWORD PReqWidth = 300;
- UWORD PReqHeight = 189;
- UBYTE *PReqWdt = (UBYTE *)"24 Bit Palette Requester";
-
- ULONG red, green, blue;
- ULONG index, ncolors;
- ULONG table[2+3];
- ULONG *originalpalette; // Allocate later for depth of screen
- int ResetPalette(void);
- int SetTable(void);
-
- struct TextAttr topaz8 = {
- ( STRPTR )"topaz.font", 8, 0x00, 0x01 };
-
- UWORD PReqGTypes[] = {
- SLIDER_KIND,
- SLIDER_KIND,
- SLIDER_KIND,
- BUTTON_KIND,
- BUTTON_KIND,
- BUTTON_KIND,
- PALETTE_KIND
- };
-
- struct NewGadget PReqNGad[] = {
- 24, 169, 243, 14, (UBYTE *)"_B", NULL, GD_BlueSliderG, PLACETEXT_LEFT, NULL, (APTR)BlueSliderGClicked,
- 24, 152, 243, 14, (UBYTE *)"_G", NULL, GD_GreenSliderG, PLACETEXT_LEFT, NULL, (APTR)GreenSliderGClicked,
- 24, 135, 243, 14, (UBYTE *)"_R", NULL, GD_RedSliderG, PLACETEXT_LEFT, NULL, (APTR)RedSliderGClicked,
- 2, 97, 86, 32, (UBYTE *)"_Use", NULL, GD_UseG, PLACETEXT_IN, NULL, (APTR)UseGClicked,
- 104, 97, 86, 32, (UBYTE *)"r_Eset", NULL, GD_ResetG, PLACETEXT_IN, NULL, (APTR)ResetGClicked,
- 203, 97, 86, 32, (UBYTE *)"_Cancel", NULL, GD_CancelG, PLACETEXT_IN, NULL, (APTR)CancelGClicked,
- 51, 3, 238, 90, NULL, NULL, GD_PaletteG, 0, NULL, (APTR)PaletteGClicked
- };
-
- ULONG PReqGTags[] = {
- (GTSL_Max), 255, (GTSL_MaxLevelLen), 3, (GTSL_LevelFormat), (ULONG)"%2lX", (GTSL_LevelPlace), (PLACETEXT_RIGHT), (PGA_Freedom), LORIENT_HORIZ, (GA_Immediate), TRUE, (GA_RelVerify), TRUE, (GT_Underscore), '_', (TAG_DONE),
- (GTSL_Max), 255, (GTSL_MaxLevelLen), 3, (GTSL_LevelFormat), (ULONG)"%2lX", (GTSL_LevelPlace), (PLACETEXT_RIGHT), (PGA_Freedom), LORIENT_HORIZ, (GA_Immediate), TRUE, (GA_RelVerify), TRUE, (GT_Underscore), '_', (TAG_DONE),
- (GTSL_Max), 255, (GTSL_MaxLevelLen), 3, (GTSL_LevelFormat), (ULONG)"%2lX", (GTSL_LevelPlace), (PLACETEXT_RIGHT), (PGA_Freedom), LORIENT_HORIZ, (GA_Immediate), TRUE, (GA_RelVerify), TRUE, (GT_Underscore), '_', (TAG_DONE),
- (GT_Underscore), '_', (TAG_DONE),
- (GT_Underscore), '_', (TAG_DONE),
- (GT_Underscore), '_', (TAG_DONE),
- (GTPA_Depth), 8, (TAG_DONE)
- };
-
- /*------------------------------------------------------------------------
- * Notice I must put my main function first so that it is the first
- * to be executed when started. Does not have to be named main().
- */
- __asm SmPalette(void)
- {
- BOOL running = TRUE;
- struct Process *proc;
- struct Message *WBMsg = NULL;
-
- proc = (struct Process *)FindTask(NULL); // Who/Where am I?
- if( !proc->pr_CLI ) // Am I started from a CLI?
- {
- WaitPort(&proc->pr_MsgPort); // NO? Well then get WBStartup Msg.
- WBMsg = GetMsg(&proc->pr_MsgPort);
- }
-
- DOSBase=(struct DOSBase *)OpenLibrary("dos.library", 0);
- if( DOSBase ) // No startup code, get DOSBase my self
- {
- IntuitionBase = (struct IntuitionBase *)OpenLibrary("intuition.library", 37);
- if( IntuitionBase )
- {
- GfxBase = (struct GfxBase *)OpenLibrary("graphics.library", 39);
- if( GfxBase )
- {
- GadToolsBase = (struct GadToolsBase *)OpenLibrary("gadtools.library", 37);
- if( GadToolsBase )
- {
- Scr = IntuitionBase->FirstScreen;
- if( (VisualInfo = GetVisualInfo( Scr, TAG_DONE)) )
- {
- ncolors = 1<< Scr->BitMap.Depth;
- PReqGTags[61] = Scr->BitMap.Depth;
- OpenPReqWindow();
- if( PReqWnd )
- {
- originalpalette = AllocVec(8+ 12*ncolors, MEMF_ANY|MEMF_CLEAR);
- if( originalpalette ) // Store original screen colors.
- {
- GetRGB32(Scr->ViewPort.ColorMap, 0, ncolors, &originalpalette[1]);
- originalpalette[0] = ncolors<<16 + 0; // Set up color table
- ResetPalette(); // Basically just set up sliders.
- while( running )
- {
- Wait(1L<<PReqWnd->UserPort->mp_SigBit);
- running = HandlePReqIDCMP();
- }
- }
- FreeVec(originalpalette);
- ClosePReqWindow();
- }
- FreeVisualInfo( VisualInfo );
- VisualInfo = NULL;
- }
- CloseLibrary((struct Library *)GadToolsBase);
- }
- CloseLibrary((struct Library *)GfxBase);
- }
- CloseLibrary((struct Library *)IntuitionBase);
- }
- CloseLibrary((struct Library *)DOSBase);
- }
-
- if( WBMsg ) // Hey! We were started from WB, clean up.
- {
- Forbid();
- ReplyMsg(WBMsg);
- Permit();
- }
-
- return(0); // Remember to exit from Main or program will continue...
- }
-
- #include "Palette_Temp.c"
-
- /*-------------------------------------------------------------------------
- * Reset palette from original colors, and put sliders in the correct place.
- */
- int
- ResetPalette(void)
- {
- LoadRGB32(&Scr->ViewPort, originalpalette);
- GetRGB32(Scr->ViewPort.ColorMap, index, 1, &table[1]);
- red = table[1]>>24;
- green = table[2]>>24;
- blue = table[3]>>24;
- SetAPen(PReqWnd->RPort, index);
- RectFill(PReqWnd->RPort, PReqWnd->BorderLeft+9, PReqWnd->BorderTop+29,
- PReqWnd->BorderLeft+41, PReqWnd->BorderTop+61);
- GT_SetGadgetAttrs(PReqGadgets[2], PReqWnd, NULL,
- GTSL_Level, red, TAG_END);
- GT_SetGadgetAttrs(PReqGadgets[1], PReqWnd, NULL,
- GTSL_Level, green, TAG_END);
- GT_SetGadgetAttrs(PReqGadgets[0], PReqWnd, NULL,
- GTSL_Level, blue, TAG_END);
- return(0);
- }
-
- /*-----------------------------------
- * Draw that little color-select box
- */
- void PReqRender( void )
- {
- UWORD offx, offy;
-
- offx = PReqWnd->BorderLeft;
- offy = PReqWnd->BorderTop;
-
-
- DrawBevelBox( PReqWnd->RPort, offx + 3, offy + 26, 45, 39, GT_VisualInfo, VisualInfo, TAG_DONE );
- DrawBevelBox( PReqWnd->RPort, offx + 7, offy + 28, 37, 35, GT_VisualInfo, VisualInfo, GTBB_Recessed, TRUE, TAG_DONE );
- }
-
- /*------------------------------
- * Act on gadget/key presses
- */
- int HandlePReqIDCMP( void )
- {
- struct IntuiMessage *m;
- int (*func)(struct IntuiMessage *);
- BOOL running = TRUE;
-
- while( m = GT_GetIMsg( PReqWnd->UserPort )) {
-
- CopyMem(( char * )m, ( char * )&PReqMsg, (long)sizeof( struct IntuiMessage ));
- GT_ReplyIMsg( m );
- switch ( PReqMsg.Class )
- {
- case IDCMP_REFRESHWINDOW:
- GT_BeginRefresh( PReqWnd );
- PReqRender();
- GT_EndRefresh( PReqWnd, TRUE );
- break;
-
- case IDCMP_CLOSEWINDOW:
- running = PReqCloseWindow();
- break;
-
- case IDCMP_VANILLAKEY: // Must handle key equivalents manualy
- switch(PReqMsg.Code)
- {
- case 'u':
- case 'U':
- running = FALSE;
- break;
- case 'e':
- case 'E':
- ResetPalette();
- running = TRUE;
- break;
- case 'c':
- case 'C':
- ResetPalette();
- running = FALSE;
- break;
- case 'r': // Move foward.
- red = (++red)&0xFF;
- GT_SetGadgetAttrs(PReqGadgets[2], PReqWnd, NULL, GTSL_Level, red, TAG_END);
- SetTable();
- break;
- case 'R': // Move backwards.
- red = (--red)&0xFF;
- GT_SetGadgetAttrs(PReqGadgets[2], PReqWnd, NULL, GTSL_Level, red, TAG_END);
- SetTable();
- break;
- case 'g':
- green = (++green)&0xFF;
- GT_SetGadgetAttrs(PReqGadgets[1], PReqWnd, NULL, GTSL_Level, green, TAG_END);
- SetTable();
- break;
- case 'G':
- green = (--green)&0xFF;
- GT_SetGadgetAttrs(PReqGadgets[1], PReqWnd, NULL, GTSL_Level, green, TAG_END);
- SetTable();
- break;
- case 'b':
- blue = (++blue)&0xFF;
- GT_SetGadgetAttrs(PReqGadgets[0], PReqWnd, NULL, GTSL_Level, blue, TAG_END);
- SetTable();
- break;
- case 'B':
- blue = (--blue)&0xFF;
- GT_SetGadgetAttrs(PReqGadgets[0], PReqWnd, NULL, GTSL_Level, blue, TAG_END);
- SetTable();
- break;
-
- default:
- break;
- }
- break;
-
- case IDCMP_MOUSEMOVE:
- case IDCMP_GADGETUP:
- case IDCMP_GADGETDOWN:
- func = ( void * )(( struct Gadget * )PReqMsg.IAddress )->UserData;
- running = func(&PReqMsg);
- break;
- }
- }
- return( running );
- }
-
- int OpenPReqWindow( void )
- {
- struct NewGadget ng;
- struct Gadget *g;
- UWORD lc, tc;
- UWORD offx = Scr->WBorLeft, offy = Scr->WBorTop + Scr->RastPort.TxHeight + 1;
-
- if ( ! ( g = CreateContext( &PReqGList )))
- return( 1L );
-
- for( lc = 0, tc = 0; lc < PReq_CNT; lc++ ) {
-
- CopyMem((char * )&PReqNGad[ lc ], (char * )&ng, (long)sizeof( struct NewGadget ));
-
- ng.ng_VisualInfo = VisualInfo;
- ng.ng_TextAttr = &topaz8;
- ng.ng_LeftEdge += offx;
- ng.ng_TopEdge += offy;
-
- PReqGadgets[ lc ] = g = CreateGadgetA((ULONG)PReqGTypes[ lc ], g, &ng, ( struct TagItem * )&PReqGTags[ tc ] );
-
- while( PReqGTags[ tc ] ) tc += 2;
- tc++;
-
- if ( NOT g )
- return( 2L );
- }
-
- if ( ! ( PReqWnd = OpenWindowTags( NULL,
- WA_Left, 0,
- WA_Top, 0,
- WA_Width, PReqWidth,
- WA_Height, PReqHeight + offy,
- WA_IDCMP, SLIDERIDCMP|BUTTONIDCMP|PALETTEIDCMP|IDCMP_CLOSEWINDOW|IDCMP_REFRESHWINDOW|IDCMP_MOUSEMOVE|IDCMP_VANILLAKEY,
- WA_Flags, WFLG_DRAGBAR|WFLG_DEPTHGADGET|WFLG_CLOSEGADGET|WFLG_SMART_REFRESH|WFLG_ACTIVATE|WFLG_RMBTRAP,
- WA_Gadgets, PReqGList,
- WA_Title, PReqWdt,
- WA_ScreenTitle, "24 Bit Palette Requester © Anthony J. Moringello",
- WA_PubScreen, Scr,
- TAG_DONE )))
- return( 4L );
-
- GT_RefreshWindow( PReqWnd, NULL );
-
- PReqRender();
-
- return( 0L );
- }
-
- void ClosePReqWindow( void )
- {
- if ( PReqWnd ) {
- CloseWindow( PReqWnd );
- PReqWnd = NULL;
- }
-
- if ( PReqGList ) {
- FreeGadgets( PReqGList );
- PReqGList = NULL;
- }
- }
-